<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>东莞新华投票系统v1.0</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/DatePicker.js" type="text/javascript"></script>
    <script src="js/checkinput.js" type="text/javascript"></script>
    <script src="js/ajaxfileupload.js" type="text/javascript"></script>
</head>

<script type="text/javascript">
    function fn(){
        if(checkinput()){
            next_step();
        }else{ return false;}
    }

    function fn2(){
        if(checkinput()){
            addItem();
        }else{ return false;}
    }

    function ajaxFileUpload(){

        $.ajaxFileUpload({
            url:'upload-img.php',
            secureuri: false,
            fileElementId: 'add_img',
            dataType:'json',
            success: function(data,status){
                $("#upload_img").attr("src",data.path);
                var src=$("#upload_img").attr("src");
                $("#del_btn").attr('disabled',false);
                $("#show_name span").html(data.name);
            },
            error: function(data,status,e){ alert(e);}
        });
    }

    function del_image(){
        var img_path = $("#upload_img").attr("src");
        $.post("del_image.php?action=del_img",{imagepath:img_path},function(msg){
            if(msg==1){
                $("#show_name span").html("成功删除图片");
                $("#upload_img").attr("src","images/default.gif");
            }else{  alert(msg);}
        })
    }

    function next_step(){
        var title = $("#sub-title").val();
        var deadDate = $("#dead-date").val();
        var option = $("#sub-option").val();
        var description = $("#description").val();
        $.ajax({
            type:'post',
            url:'add-subvote.php',
            dataType:'json',
            data:{
                "title":title,
                "description":description,
                "option":option,
                "deadDate":deadDate
            },
            success:function(data){
                if(data.success==1){
                    $("#step2").show();
                    $("#vsid").val(data.vsid);
                    $("#next_step_btn").attr('disabled','disabled');
                    $("#item-title").addClass("noempty");
                }else{
                    alert("提交投票主题失败！");
                }
            },
            error:function(e){
                alert(e);
            }
        });

    }

    function addItem(){
        var title = $("#item-title").val();
        var vsID   = $("#vsid").val();
        var viDES  = $("#item-description").val();
        var image = $("#show_name span").html();
        $.ajax({
            type:'post',
            url:'add-item.php',
            dataType:'json',
            data:{"title":title,"vsID":vsID,"viDES":viDES,"image":image},
            success:function(json){
                if(json.success==1){
                    alert("添加成功！");
                    $("#item-title,#item-description").val("");
                    $("#upload_img").attr("src","images/default.gif");
                    $("#show_name span").html("默认图片");
                    $("#del_btn").attr('disabled','disabled');
                }else{
                    alert("添加选项失败！");
                }

            }
        });
    }
</script>

<body id="vote-type2">
<?php
    if(!isset($_COOKIE['islogin']) || $_COOKIE['islogin']!=1){
        echo "<script>window.location.href='login.php';</script>";
    }
?>

<div id="nav">
    <div id="nav_top">
        <div class="width navs">
            <div class="logo">
                <a href="index.php" target="ifm"><img src="images/logo.png" width="290" height="54" /></a>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div id="header">
        <div class="width">
            <div style="background: url(images/gx.gif) no-repeat; height: 48px;">
                <span style="float: right; font-size: 12px;">欢迎您：<?php echo $_COOKIE["username"];?>---<a href="rep-password.php?action=<?php echo $_COOKIE['username'];?>">修改密码</a>---<a href="login.php?action=logout">退出</a></span>
                <div id="top-nav">
                    <a id="1" href="index.php">首页</a>
                    <a id="2" href="my-vote.php">我的投票</a>
                    <a id="3" href="create-vote.php" class="curr">创建投票</a>
                    <a id="4" href="manager-vote.php">管理投票</a>
                </div>
            </div>
        </div>
    </div>
</div>


<div id="content">
    <div id="main-content">
        <form action="add-vote.php" method="post" enctype="multipart/form-data">
            <fieldset id="step1">
                <h3>步骤一：设置基本信息(必填)</h3>
                <div><label for="sub-title">投票标题：</label><input id="sub-title" class="noempty" name="sub-title" type="text" /><span style="color:red;padding-left:30px;font-size:12px;">说明：请输入小于50个字符的标题。</span></div>
                <div><label for="dead-date">截止日期：</label><input id="dead-date" class="noempty" name="dead-date" type="text" onclick="setday(this)" readonly="readonly" /><span style="color:red;padding-left:30px;font-size:12px;">说明：日期必须等于或大于今天。格式例子:2014-9-9</span></div>
                <div><label for="option">投票类型：</label><select id="sub-option"><option value="1" selected>单选题</option><option value="2">多选题</option><option value="3">判断题</option></select></div>
                <div><label style="vertical-align:top;" for="description">投票说明：</label><textarea class="noempty" name="description" id="description" cols="55" rows="5"></textarea><span style="color:red;padding-left:30px;font-size:12px;vertical-align:top;">说明：请输入小于200个字符，内容包括投票目的和规则。</span></div>
                <div><button id="next_step_btn" class="btn btn-warning step-btn" type="button" onclick="fn()">下一步</button></div>
            </fieldset>
            <fieldset id="step2">
                <h3>步骤二：添加选题项目</h3>
                <div class="left-content">
                    <div style="margin-left:0;margin-right:0;margin-top:0;vertical-align:middle;" class="width870"><label for="title">题目： </label><input id="title" name="title" type="text"/><label>正确答案：</label for="answer"><input style="width:50px;" type="text" id="answer" name="answer" /><label for="options">选项个数：</label><input style="width:50px;" type="text" id="options" name="options" /><button type="button" class="btn btn-success btn-xs">添加</button></button></div>
                    <div style="margin-left:0;margin-right:0;margin-top:0;border:1px solid gray;" class="width870" id="options">
                        <div><label>A：</label><input type="text"/> </div>
                        <div><label>A：</label><input type="text"/> </div>
                        <div><label>A：</label><input type="text"/> </div>
                        <div><label>A：</label><input type="text"/> </div>
                    </div>
                    <div style="margin-left:0;margin-right:0;" class="width870"><button type="button" class="btn btn-info step-btn" onclick="fn2()" >确定</button></div>
                </div>
            </fieldset>
        </form>
    </div>
</div>

<!--详细内容模块end-->
<div id="footer" class="clear">
    <div
        style="background: url(images/gx_footer.gif) no-repeat; width: auto; height: 118px; padding: 20px 0 0 0;">
        <div class="width">
            <div style="text-align: center; font-size: 14px;">
                <a href="http://10.44.152.49">东莞新华导航页</a> <a
                    href="http://10.44.152.252./purchase" class="a1" target="ifm">采购立项签报系统</a> <a
                    href="http://10.44.152.166:8080/che/">用车管理系统</a> <a href="http://10.44.152.166:8080/caigou/"
                    >采购随机筛选系统</a>
            </div>
            <div style="margin: 15px 0 0 0; font-size: 11px; text-align: center;">新华人寿保险股份有限公司东莞中心支公司
                版权所有 东莞新华办公室
            </div>
        </div>
    </div>
</div>
</body>
</html>